home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu745.dms / pu745.adf / GLOBE099.LHA / Ami-Globe / convert_bin.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  5KB  |  167 lines

  1. /* Convertion d'une serie de pt qui est a la precision maximum a une */
  2. /* serie de points qui ne garde que les point de precision 5            */
  3.  
  4. #include <exec/types.h>
  5.  
  6. /* ANSI C */
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <ctype.h>
  11.  
  12. #define MAX_PT  10000
  13.  
  14. int tst_end(
  15.         FILE    *input
  16.         )
  17. {
  18.         char c;
  19.         int     code_ret;
  20.  
  21.         /* lecture du prochain caractere */
  22.         do
  23.     {
  24.                 c=getc(input);
  25.                 if (c==EOF)
  26.             return(TRUE);
  27.                 if (c=='#')
  28.         {
  29.                         do
  30.             {
  31.                                 c=getc(input);
  32.                         }
  33.               while((c!=0x0a)&&(c!=EOF));
  34.                         c=getc(input);
  35.                 }
  36.  
  37.         }
  38.       while((!isalnum(c))&&(c!='E'));
  39.         if ((!isalpha(c))||(c!='E'))
  40.     {
  41.                 ungetc(c,input);
  42.                 code_ret=FALSE;
  43.         }
  44.     else
  45.     {
  46.                 code_ret=TRUE;
  47.         }
  48.         return(code_ret);
  49. }
  50.  
  51. void convert_map(
  52.         char *p_filename,
  53.         char *out_filename
  54.         )
  55. {
  56.         FILE    *input;
  57.         FILE    *output;
  58.         char    c1,c2,c;
  59.         BOOL    flg_end,flg_border,flg_zone;
  60.         int     num_border;
  61.         short   int     num_pt;
  62.         short   int     *tab_temp;
  63.         int     mx,my,MX,MY;
  64.         int     x,y,code;
  65.         short   int     tab_format[4];
  66.  
  67.         flg_end=FALSE;
  68.  
  69.         input = fopen(p_filename,"r");
  70.         output = fopen(out_filename,"w");
  71.         if  (input && output )
  72.     {
  73.                 tab_temp=malloc(sizeof(short int)*MAX_PT*3);
  74.  
  75.                 /* Premiere chose, la taille max de notre carte...*/
  76.  
  77.                 fscanf( input ,"%d %d %d %d"  ,&mx,&my,&MX,&MY);
  78.                 tab_format[0]=mx;
  79.                 tab_format[1]=my;
  80.                 tab_format[2]=MX;
  81.                 tab_format[3]=MY;
  82.                 fwrite( tab_format,sizeof(short int),4,output);
  83.                 //printf("%ld%ld%ld%ld\n"  ,mx,my,MX,MY);
  84.  
  85.  
  86.                 //printf("Lecture des borders\n");
  87.                 flg_zone=TRUE;
  88.                 num_border=0;
  89.         
  90.         /* BIZARRE: la zone de données ne semble commencer qu'au 16 eme
  91.         octet */
  92.                 do
  93.         {
  94.                         flg_border=TRUE;
  95.                         num_pt=0;
  96.                         do
  97.             {
  98.                                 c1=getc(input);
  99.                                 c2=getc(input);
  100.                                 if(c2=='#')
  101.                 {
  102.                                     do
  103.                     {
  104.                                                 c=getc(input);
  105.                                         }
  106.                       while  ((c!=0x0a)&&(c!=EOF));
  107.                                         flg_border=FALSE;
  108.  
  109.                                 }
  110.                 else
  111.                 {
  112.                                         ungetc(c2,input);
  113.                                         ungetc(c1,input);
  114.                                 
  115.                                         fscanf(input,"%d %d %d",&code,&x,&y);
  116.                                         tab_temp[num_pt*3+0]=code;
  117.                                         tab_temp[num_pt*3+1]=x;
  118.                                         tab_temp[num_pt*3+2]=-y;
  119.                                         if (num_pt>MAX_PT)
  120.                     {
  121.                                                 /*printf("ERREUR:Depassement du nb max de pt\n");*/
  122.                                         }
  123.                     else
  124.                     {
  125.                                                 num_pt++;
  126.                                         }
  127.  
  128.                                 }
  129.                         }
  130.               while(flg_border==TRUE);
  131.  
  132.                 
  133.                         /* On s'assure que le dernier point est bien de niveau 5 */
  134.                         if (tab_temp[(num_pt-1)*3+0]<5)
  135.             {
  136.                                 tab_temp[(num_pt-1)*3+0]=5;
  137.                         }
  138.                         /*printf("Border[%d]:%d pt\n",num_border,num_pt);*/
  139.                         fwrite(&num_pt ,sizeof(short int)  ,1     ,output);
  140.                         fwrite(tab_temp,sizeof(short int)*3,num_pt,output);
  141.  
  142.                         num_border++;
  143.  
  144.                         if(tst_end(input)==TRUE){
  145.                                 /*printf("End of border def\n");*/
  146.                                 flg_zone=FALSE;
  147.                         }
  148.  
  149.                 }
  150.           while(flg_zone==TRUE);
  151.                 fclose(input);
  152.                 fclose(output);
  153.         }
  154. }
  155.  
  156. main(int        argc,char **argv)
  157. {
  158.         if (argc!=3)
  159.     {
  160.                 printf("Conversion fichier .data\nUsage %s <fichier source> <fichier dest>\n",argv[0]);
  161.         }
  162.     else
  163.     {
  164.                 convert_map(argv[1],argv[2]);
  165.         }
  166. }
  167.